<template lang="pug">
  el-form-item(ref="formItem" v-if='!scope' :class="config.label?'':'form-label-hidden'"  :prop="config.propertyName" :rules="rules" label-width="0px")
    van-field(ref="input" @input="input" @blur="blur"  @focus="focus" @keydown.native="keydown" @keyup.native="keyup"  @click.native="readonly && $event.target.blur()" @touchstart.native="readonly && $event.target.blur()" :required="required" v-model="rootForm.properties[config.propertyName]" :title="rootForm.properties[config.propertyName]" :type="config.inputType" :rows="3"  :label="config.label" :placeholder="readonly?' ':config.placeholder" :readonly="readonly")
      span(slot="button" v-if="config.inputType === 'text'") {{config.suffix}}
  //- el-form-item(ref="formItem" v-else  :prop="config.propertyName" :rules="rules" label-width="0px")
  div(v-else)
    van-field(ref="input" @input="input" @blur="blur" @focus="focus" @keydown.native="keydown" @keyup.native="keyup" @click.native="readonly && $event.target.blur()" @touchstart.native="readonly && $event.target.blur()" :required="required" v-model="scope[config.propertyName]" :title="scope[config.propertyName]" :type="config.inputType" :rows="3"  :label="config.label" :placeholder="readonly?' ':config.placeholder" :readonly="readonly")
      span(slot="button" v-if="config.inputType === 'text'") {{config.suffix}}
    .scope-error-message {{scopeErrorMessage}}
</template>
<script>
import normalRenderCommon from '../common/normalRenderCommon'

export default {
  mixins: [normalRenderCommon],
  methods: {
    input(value) {
      if (!this.scope) {
        this.$refs.formItem.$emit('el.form.change', [value])
      } else {
        this.validate()
      }
      return this.config.inputCb && this.getParsedFn('inputCb')(value)
    },
    blur() {
      if (!this.scope) {
        this.$refs.formItem.$emit('el.form.blur', [this.rootForm.properties[this.config.propertyName]])
      } else {
        this.validate()
      }
      return this.config.blurCb && this.getParsedFn('blurCb')()
      // return this.config.blurCb && !!(new Function('__properties', '__row', 'with(__properties) {return (' + this.config.blurCb + ')() }'))(this.rootForm.properties, this.scope)
    }
  },
}
</script>
<style lang="scss">
  .scope-error-message {
    color: #EF0000;
    font-size: 12px;
    height: 16px;
    line-height: 16px;
  }
</style>
